<!--用户信息（头像和个性签名）-->
<script setup lang="ts">
import {defineEmits, inject, onMounted, ref} from "vue";
import api from "@/api";
import {BASE_URL} from "@/api/config";
import useSettingStore from '@/app/setting/setting.store'
import useTaskStore from '@/store/task'

//
const emit = defineEmits(['change'])
let activeKey = ref<string>('Session')
const change = (key: string) => {
  activeKey.value = key
  emit('change', key)
}

//业务代码
const userInfo = inject('userInfo')
//头像url
const avatarUrl = ref('')
//获取头像
const getAvatar = async () => {
  const res = await api.getFile({uuid: userInfo.value.avatar})
  avatarUrl.value = BASE_URL + res.data.data.path
  console.log(avatarUrl.value)
}
//点击打开资料编辑
const settingStore = useSettingStore()
const taskStore = useTaskStore()
const navToProfile = () => {
  settingStore.setSelectedKeys('ProfileSetting')
  settingStore.setOpenKeys('profile')
  taskStore.OPEN_APP('setting')
}

onMounted(() => {
  getAvatar()
})
</script>
<template>
  <div class="user-info">
    <div class="left-info">
      <div class="avatar" @click.stop="navToProfile">
        <img :src="avatarUrl">
      </div>
    </div>
    <div class="right-info" @click.stop="navToProfile">
      <div class="nickname">{{ userInfo.nickname }}</div>
      <div class="status">{{ userInfo.signature }}</div>
    </div>
  </div>
  <div class="control">
    <div class="control-item " @click="change('Session')">
      <div :class="{'control-item-icon':true,'active1':activeKey === 'Session'}">
        <span class="material-icons" style="color: #2F71F2">chat</span>
      </div>
    </div>
    <div class="control-item" @click="change('Contacts')">
      <div :class="{'control-item-icon':true,'active2':activeKey === 'Contacts'}">
        <span class="material-icons" style="color: #26B383">group</span>
      </div>
    </div>
    <div class="control-item" @click="change('Func')">
      <div :class="{'control-item-icon':true,'active3':activeKey === 'Func'}">
        <span class="material-icons" style="color: #FE9F1A">grid_view</span>
      </div>
    </div>
  </div>
</template>
<style lang="less" scoped>
.user-info {
  width: 240px;
  height: 70px;
  display: flex;
  align-items: center;
  //border-bottom: 1px solid #D9D9D9;

  .left-info {
    width: 70px;
    height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;

    .avatar {
      cursor: pointer;
      width: 50px;
      height: 50px;
      border-radius: 50%;
      overflow: hidden;
      box-sizing: content-box;

      img {
        width: 50px;
        height: 50px;
      }
    }

    .avatar:hover {
      border: 2px solid #2F71F2;

      img:hover {
        opacity: 0.8;
      }
    }

    .avatar:active {
      border: 1px solid #2F71F2;

      img:hover {
        opacity: 1;
      }
    }
  }

  .right-info {
    height: 70px;
    width: 170px;
    padding: 8px 8px 8px 0;

    .nickname {
      font-size: 18px;
      font-weight: 600;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }

    .status {
      color: #8A8F99;
      font-size: 12px;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
  }
}

.control {
  width: 240px;
  height: 60px;
  display: flex;
  justify-content: space-around;

  .control-item {
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;

    .control-item-icon {
      width: 70px;
      height: 45px;
      user-select: none;
      text-align: center;
      cursor: pointer;
      border-radius: 10px;

      .material-icons {
        font-size: 35px;
        height: 45px;
        line-height: 45px;
      }
    }

    .active1 {
      background-color: #D1E8FF;
    }

    .active2 {
      background-color: #D3FAE7;
    }

    .active3 {
      background-color: #FFEFD1;
    }

  }
}

</style>
